package cn.shop.gateway;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.setting.Setting;

import java.io.File;

/**
 * @author : 李一涵
 * @date : Created in 2021-12-15 17:50
 * @description :
 */
public class Config {

    private static Setting setting;

    private Config() {}

    public static void init() {
        setting = new Setting(new File("gateway.setting"), CharsetUtil.CHARSET_UTF_8, true);
        setting.autoLoad(true);
    }

    public static Setting getSetting() {
        return setting;
    }

    public static int getInt(String key) {
        if (setting == null) {
            return 0;
        }
        return setting.getInt(key);
    }

    public static long getLong(String key) {
        if (setting == null) {
            return 0L;
        }
        return setting.getLong(key);
    }

    public static String getString(String key) {
        if (setting == null) {
            return "";
        }
        return setting.getStr(key);
    }

    public static void setPort(String port) {
        setting.set("server.port", port);
    }

    public static void store() {
        setting.store();
    }
}
